package com.doudou.pay.helper.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Component
@EnableWebSocket
public class PayWebsocketConfig implements WebSocketConfigurer{
	
	@Autowired
	private PayWebsocketHandler payWebsocketHandler;
	
	@Autowired
	private HandshakeInterceptor handshakeInterceptor;

	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
		registry.addHandler(payWebsocketHandler, "/ws")
				.setAllowedOrigins("*")
				.addInterceptors(this.handshakeInterceptor);
		
		registry.addHandler(payWebsocketHandler, "/ws/sockjs")
				.addInterceptors(this.handshakeInterceptor)
				.withSockJS();
	}
	

}
